package com.cy.pj.controller;
import com.cy.pj.controller.pojo.Brand;
import com.cy.pj.controller.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class BrandController {

    @Autowired
    private BrandService brandService;

    //http://localhost/brand/doFindBrands?name=tcl 传统方式url
    //http://localhost/brand/doFindBrands/tcl rest风格url
    //rest风格(一种软件架构编码风格)的url定义
    //其语法为:a/b/{c}/d/{e},在url可以定义变量,这个变量需要使用{}括起来
    //rest风格可以更好实现跨平台
    //@PathVariable 注解用于修饰方法参数,目的是告诉spring mvc,参数的值来自url
    @GetMapping(value={"/‘7/{name}","/brand/doFindBrands"})
    public String doFindBrands(@PathVariable(required = false) String name, Model model){
        List<Brand> list=brandService.findBrands(name);
        model.addAttribute("list", list);
        return "brand/brand";//第一个brand为目录,第二brand为view name
    }

}